/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.control.Calculation;

import simplemetrosystem.model.Element.*;

/**
 *
 * @author Eric Qian
 */
public class SuperEdge {

    public SuperEdge(MetroEdge[] edges) {
        this.edges = edges;
    }

    public MetroStation getStationA() {
        return edges[0].getStationA();
    }

    public MetroStation getStationB() {
        return edges[edges.length - 1].getStationB();
    }

    public MetroLine getLine() {
        return edges[0].getLine();
    }

    public double getDistance() {
        double distance = 0;
        for (int i = 0; i < edges.length; i++) {
            distance += edges[i].getDistance();
        }
        return distance;
    }

    public double getTime() {
        double time = 0;
        for (int i = 0; i < edges.length; i++) {
            time += edges[i].getTime();
        }
        return time;
    }

    public int containStation(MetroStation station) {
        for (int i = 0; i < edges.length; i++) {
            if (edges[i].getStationA() == station) {
                return i;
            }
        }
        return -1;
    }

    public MetroEdge[] getSubEdges(int i, boolean sub) {
        MetroEdge[] aEdges;
        if (sub) {
            aEdges = new MetroEdge[i];
            for (int j = 0; j < i; j++) {
                aEdges[j] = edges[j];
            }
        } else {
            aEdges = new MetroEdge[edges.length - i];
            for (int j = i; j < edges.length; j++) {
                aEdges[j - i] = edges[j];
            }
        }
        return aEdges;
    }

    public int getEdgeSize() {
        return edges.length;
    }

    public MetroEdge getEdgeAt(int i) {
        return edges[i];
    }
    private MetroEdge[] edges;
}